package com.hlhj.carview.aty

import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.widget.Toast
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Iview.UserView
import com.hlhj.carview.Iview.WalletView
import com.hlhj.carview.R
import com.hlhj.carview.adapter.RuleAdp
import com.hlhj.carview.bean.MyBaseBean
import com.hlhj.carview.bean.UserInfoBean
import com.hlhj.carview.presenter.UserPresetner
import com.hlhj.carview.presenter.WalletPresenter
import kotlinx.android.synthetic.main.aty_wallet.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 * Created by Never Fear   on 2018\12\20 0020.
Never More....
 */
class WalletAty :BaseAty<WalletView,WalletPresenter>(), WalletView, UserView {
    private var all=""
    override fun setUser(userInfoBean: UserInfoBean) {
        tvPrice?.text = userInfoBean.info.balance
        all=userInfoBean.info.balance
    }

    override fun setChangeResult(myBaseBean: MyBaseBean) {

    }

    private var userPresenter:UserPresetner?=null

    private var adp :RuleAdp?=null
    private val datas=ArrayList<String>()
    override fun setRule(myBaseBean: MyBaseBean) {

    }

    override fun initView() {
        btRightText.text="钱包明细"
        adp= RuleAdp(datas)
        ruleList.adapter=adp
        ruleList.layoutManager=LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        val s="用户您好，途途配送的提现规则如下 <br></br>" +
                "1.提现申请审核周期：早9:00-晚18:00<br></br>" +
                "2.提现到账时间：提现成功后一般将在1-3个工作日到账，周末顺延。如逾期未到账，请联系工作人员<br></br>" +
                "3.提现支持微信、支付宝账号提现"

        webView?.loadDataWithBaseURL(null, s, "text/html", "UTF-8", null);
        tvPrice?.text="0元"
    }

    override fun logicStart() {
    }

    override fun setListener() {
        btGain.setOnClickListener {
            val intent = Intent(this, GainAty::class.java)
            startActivity(intent)
        }
        btRightText.setOnClickListener {
            val intent = Intent(this, GainAty::class.java)
            startActivity(intent)
        }
        btGetCash.setOnClickListener {
            val intent = Intent(this, GetCashAty::class.java)
            intent.putExtra("all",all)
            startActivityForResult(intent,1)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (resultCode!=-1)return
        if (requestCode==1){
            setResult(-1)
            userPresenter?.getUser(this@WalletAty)
        }
    }
    override fun bindView(): WalletView {
        return this
    }
    override fun createPresenter(): WalletPresenter {
        userPresenter= UserPresetner()
        userPresenter?.let {
            it.createModule()
            it.bindView(this@WalletAty)
        }
        return WalletPresenter()
    }
    override fun getContentID(): Int {
        return R.layout.aty_wallet
    }
}